/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
  \file ant_point.h
	\brief header file for ant_point

                    \author Maciej Stachura
             $Date: 2010/02/04 13:34:45 $
*/

#ifndef __ANTENNA_CMD_H
#define __ANTENNA_CMD_H

#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>

#include "String.h"
#include "command.h"
#include "queue.h"
#include "type_defs.h"
#include "threadedPipe.h"
#include "shmStruct.h"

#include "WMMHeader.h"

class AntennaCmd : public ThreadedPipe
{
private:
	typedef enum { STANDBY=0, TRACK} TrackerMode;

  ClientList tracked_vehicles;
  Client * requester;
	TimeStamp last_tracking_loop;
	TimeStamp last_client_update;
	TimeStamp last_mag_update;

  MagStruct_t mag;
	GPSTelem_t last_gps_update;

	TrackerMode tracker_mode;

  AntPoint_t antenna;

	void TrackTargets(float azimuth, float elevation);
  float WMM_mag_var(float lat_d, float lon_d, float alt_km, float year);

  float mag_var;

	void PrintMode(TrackerMode mode);

	float omni_range;
	PointingType pointing_type;
	uint8_t system_type;

	float manual_offset;
	bool pause_tracking;

	void connectToGS(String ipStr, String portStr, bool connect);

public:
	AntennaCmd(String name, PointingType type = RELATIVE, float omni_range = 0, uint8_t systype = CMD_ANT_APS_TELEM);
	~AntennaCmd() {}
					 
  bool init(ShmStruct * shmStructPtr);
  void parseInternalData(const Command &cmd);
	void update();
};

#endif
